package com.timo.redis.controller;

import com.timo.redis.model.Person;
import com.timo.redis.util.RedisUtil;
import com.timo.redis.util.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @Description: 类的详细说明
 * @Author: timo
 * @Date: 2019/8/29 10:16
 */
@RestController
@RequestMapping("/redis/list")
public class RedisListController {

    @Resource
    private RedisUtil redisUtil;

    @GetMapping("/add")
    public Result add() {
        Person person_1 = new Person("20190829_001", "山无棱天地合");
        Person person_2 = new Person("20190829_002", "山无棱天地合2");
        Person person_3 = new Person("20190829_003", "山无棱天地合3");
        Person person_4 = new Person("20190829_004", "山无棱天地合4");

        List<Person> saveList = new ArrayList();

        saveList.add(person_1);
        saveList.add(person_2);
        saveList.add(person_3);
        saveList.add(person_4);

        redisUtil.lset("person_list_1", saveList);

        return Result.success();
    }


    @GetMapping("/get/{key}")
    public Result get(@PathVariable String key) {
        List<Person> lsit = redisUtil.lget(key, List.class);
        return Result.success(lsit);
    }
}
